package com.hongkzh.www.adv.controller;

import com.hongkzh.www.adv.service.AdvService;
import com.hongkzh.www.adv.service.CarouselService;
import com.hongkzh.www.conmon.MathRandom;
import com.hongkzh.www.conmon.ReqResponse;
import com.hongkzh.www.swagger.annotation.*;
import com.jfinal.core.Controller;
import com.jfinal.plugin.activerecord.Page;
import com.jfinal.plugin.activerecord.Record;

import java.util.List;

/**
 * @author martins
 */
@Api(tag = "adv", description = "乐看主页广告列表")
public class AdvController extends Controller {
    static AdvService advService=new AdvService();

    static CarouselService carouselService=new CarouselService();
    @ApiOperation(url = "/v1/adv/getCarouselList", tag = "adv", httpMethod = "post",description = "乐看主页获取轮播图")

    @ApiResponses({
            @ApiResponse(code=200,message="成功",responseHeaders={
                    @ResponseHeader(name="code",description = " 0成功 1失败"),
                    @ResponseHeader(name="data",description = "{ imgSrc 图片地址 ,imgLinks 图片链接  id 视频id  imgRank 图片排序 title 标题 vedioLength  视频长度   type  1自媒体 2企业广告3城市广告4传统文化  }"),
                    @ResponseHeader(name="msg",description = "失败原因") })

    })
    public void getCarouselList(){
        ReqResponse<List<Record>> r=new ReqResponse();
        List<Record>  record= carouselService.getCarouselList();
        r.setData(record);
        renderJson(r);
    }


   /* @ApiOperation(url = "/v1/carousel/getCategoryList", tag = "carousel", httpMethod = "post",description = "获取主页分类")

    @ApiResponses({
            @ApiResponse(code=200,message="成功",responseHeaders={
                    @ResponseHeader(name="code",description = " 0成功 1失败"),
                    @ResponseHeader(name="data",description = "{ imgSrc 图片地址 ,imgLinks H5链接 imgRank 图片排序 category 分类名称  id  ,type  1自媒体 2企业广告3城市广告4传统文化 10 h5 }"),
                    @ResponseHeader(name="msg",description = "失败原因") })

    })
    public void getCategoryList(){
        ReqResponse<List<Record>> r=new ReqResponse();
        List<Record>  record= carouselService.getCategoryList();
        r.setData(record);
        renderJson(r);
    }*/

    @ApiOperation(url = "/v1/adv/getRecommendList", tag = "adv", httpMethod = "post",description = "乐看主页获取主页推荐广告列表")
    @Params({
            @Param(name = "pageNumber", description = "页码", required = true, dataType = "string")
    })
    @ApiResponses({
            @ApiResponse(code=200,message="成功",responseHeaders={
                    @ResponseHeader(name="code",description = " 0成功 1失败"),
                    @ResponseHeader(name="data",description = "totalRow 总行数  pageNumber第几页 firstPage 是否第一页 lastPage 是否最后一页 totalPage 总页数 pageSize每页条数  list[{ showType 1视频 2网页 categoryName 类别名称 coverImgSrc 图片地址 vedioLength  视频长度 lastIntegralCount 剩余积分  playCount播放总数 coverLink 图片链接  imgSrc 视频地址 ,imgLinks 视频链接 imgRank 图片排序 title 标题 imgNote 副标题 headImg 头像   uid 自媒体或者企业id uName 用户名称 playCount 播放总数 type 类型  1自媒体 2企业广告3城市广告4传统文化 utype 用户类型 1自媒体 2企业广告3城市广告4传统文化 id 视频id  staticAdv { coverImgSrc 图片地址 coverLink 图片链接  imgSrc 视频地址 ,imgLinks 视频链接 imgRank 图片排序 title 标题 imgNote 副标题 type 类型  1自媒体 2企业广告3城市广告4传统文化 }}]"),
                    @ResponseHeader(name="msg",description = "失败原因") })

    })
    public void getRecommendList(){
        int pageNumber=getParaToInt("pageNumber");
        ReqResponse<Page<Record>> r=new ReqResponse();
        Page<Record>  record= advService.getRecommendList(pageNumber);
        List<Record>  statics= advService.getStaticListByType("0");
        for (Record record1:record.getList()
             ) {
            record1.set("staticAdv", null);
            for (Record static1:statics
                 ) {

                if(0==MathRandom.PercentageRandom()) {
                    record1.set("staticAdv", static1);
                }
            }

        }
        r.setData(record);
        renderJson(r);
    }
    /*@ApiOperation(url = "/v1/adv/getStaticList", tag = "adv", httpMethod = "post",description = "获取主页静态广告列表")
    @ApiResponses({
            @ApiResponse(code=200,message="成功",responseHeaders={
                    @ResponseHeader(name="code",description = " 0成功 1失败"),
                    @ResponseHeader(name="data",description = "{ coverImgSrc 图片地址 coverLink 图片链接  imgSrc 视频地址 ,imgLinks 视频链接 imgRank 图片排序 title 标题 imgNote 副标题 }]"),
                    @ResponseHeader(name="msg",description = "失败原因") })

    })
    public void getStaticList(){
        ReqResponse<List<Record>> r=new ReqResponse();
        List<Record>  record= advService.getStaticList();
        r.setData(record);
        renderJson(r);
    }
    @ApiOperation(url = "/v1/adv/getCityAdvList", tag = "adv", httpMethod = "post",description = "获取主页城市广告列表")
    @ApiResponses({
            @ApiResponse(code=200,message="成功",responseHeaders={
                    @ResponseHeader(name="code",description = " 0成功 1失败"),
                    @ResponseHeader(name="data",description = "{headImg 头像   uid 自媒体或者企业id uName 用户名称  coverImgSrc 图片地址 coverLink 图片链接  imgSrc 视频地址 ,imgLinks 视频链接 imgRank 图片排序 title 标题 imgNote 副标题 playCount 播放总数 id 视频id tags 标签  : [  {  label :  旅游城市 ,  d :  1   } }"),
                    @ResponseHeader(name="msg",description = "失败原因") })

    })
    public void getCityAdvList(){
        ReqResponse<List<Record>> r=new ReqResponse();
        List<Record>  record= advService.getCityAdvList();
        r.setData(record);
        renderJson(r);
    }

    @ApiOperation(url = "/v1/adv/getCityList", tag = "adv", httpMethod = "post",description = "获取主页城市列表")
    @ApiResponses({
            @ApiResponse(code=200,message="成功",responseHeaders={
                    @ResponseHeader(name="code",description = " 0成功 1失败"),
                    @ResponseHeader(name="data",description = "{  imgSrc 图片地址 ,  imgRank 图片排序 name 标题 imgNote 副标题  }"),
                    @ResponseHeader(name="msg",description = "失败原因") })

    })
    public void getCityList(){
        ReqResponse<List<Record>> r=new ReqResponse();
        List<Record>  record= advService.getCityList();
        r.setData(record);
        renderJson(r);
    }

    @ApiOperation(url = "/v1/adv/getMediaList", tag = "adv", httpMethod = "post",description = "获取主页自媒体广告列表")
    @ApiResponses({
            @ApiResponse(code=200,message="成功",responseHeaders={
                    @ResponseHeader(name="code",description = " 0成功 1失败"),
                    @ResponseHeader(name="data",description = "{ headImg 头像   uid 自媒体或者企业id uName 用户名称 id 视频id coverImgSrc 图片地址 coverLink 图片链接  imgSrc 视频地址 ,imgLinks 视频链接 imgRank 图片排序 title 标题 imgNote 副标题 playCount 播放总数 }"),
                    @ResponseHeader(name="msg",description = "失败原因") })

    })
    public void getMediaList(){
        ReqResponse<List<Record>> r=new ReqResponse();
        List<Record>  record= advService.getMediaList();
        r.setData(record);
        renderJson(r);
    }
    @ApiOperation(url = "/v1/adv/getEnterpriseList", tag = "adv", httpMethod = "post",description = "获取主页企业广告列表")
    @ApiResponses({
            @ApiResponse(code=200,message="成功",responseHeaders={
                    @ResponseHeader(name="code",description = " 0成功 1失败"),
                    @ResponseHeader(name="data",description = "{ headImg 头像   uid 自媒体或者企业id uName 用户名称 id 视频id coverImgSrc 图片地址 coverLink 图片链接  imgSrc 视频地址 ,imgLinks 视频链接 imgRank 图片排序 title 标题 imgNote 副标题 playCount 播放总数}"),
                    @ResponseHeader(name="msg",description = "失败原因") })

    })
    public void getEnterpriseList(){
        ReqResponse<List<Record>> r=new ReqResponse();
        List<Record>  record= advService.getEnterpriseList();
        r.setData(record);
        renderJson(r);
    }
    @ApiOperation(url = "/v1/adv/getTraditionList", tag = "adv", httpMethod = "post",description = "获取主页传统广告列表")
    @ApiResponses({
            @ApiResponse(code=200,message="成功",responseHeaders={
                    @ResponseHeader(name="code",description = " 0成功 1失败"),
                    @ResponseHeader(name="data",description = "{ headImg 头像   uid 自媒体或者企业id uName 用户名称 id 视频id coverImgSrc 图片地址 coverLink 图片链接  imgSrc 视频地址 ,imgLinks 视频链接 imgRank 图片排序 title 标题 imgNote 副标题 playCount 播放总数 }"),
                    @ResponseHeader(name="msg",description = "失败原因") })

    })
    public void getTraditionList(){
        ReqResponse<List<Record>> r=new ReqResponse();
        List<Record>  record= advService.getTraditionList();
        r.setData(record);
        renderJson(r);
    }*/

    @ApiOperation(url = "/v1/adv/getHotAdvList", tag = "adv", httpMethod = "post",description = "乐看主页获取主页热点分页列表")
    @Params({
            @Param(name = "pageNumber", description = "页码", required = true, dataType = "string")
    })
    @ApiResponses({
            @ApiResponse(code=200,message="成功",responseHeaders={
                    @ResponseHeader(name="code",description = " 0成功 1失败"),
                    @ResponseHeader(name="data",description = "totalRow 总行数  pageNumber第几页 firstPage 是否第一页 lastPage 是否最后一页 totalPage 总页数 pageSize每页条数  list[{ categoryName 分类名称 headImg 头像  vedioLength  视频长度 playCount播放总数  uid 自媒体或者企业id uName 用户名称 id 视频id coverImgSrc 图片地址 coverLink 图片链接  imgSrc 视频地址 ,imgLinks 视频链接 imgRank 图片排序 title 标题 imgNote 副标题  type 类型  1自媒体 2企业广告3城市广告4传统文化 }]"),
                    @ResponseHeader(name="msg",description = "失败原因") })

    })
    public void getHotAdvList(){
        int pageNumber=getParaToInt("pageNumber");
        ReqResponse<Page<Record>> r=new ReqResponse();
        Page<Record> record= advService.getHotAdvList(pageNumber);
        r.setData(record);
        renderJson(r);
    }
/*


    @ApiOperation(url = "/v1/adv/getAdvCommentsById", tag = "adv", httpMethod = "post",description = "获取播放视频评论信息")
    @Params({
            @Param(name = "id", description = "视频id", required = true, dataType = "string"),
            @Param(name = "pageNumber", description = "页码", required = true, dataType = "string")
    })
    @ApiResponses({
            @ApiResponse(code=200,message="成功",responseHeaders={
                    @ResponseHeader(name="code",description = " 0成功 1失败"),
                    @ResponseHeader(name="data",description = "  totalRow 总行数  pageNumber第几页 firstPage 是否第一页 lastPage 是否最后一页 totalPage 总页数 pageSize每页条数  list[{id 记录id userId 评论用户 uName 评论用户名称 headImg 评论用户头像 content 内容 replyUserId 回复id rName回复用户名称 rheadImg回复用户头像 createDate 创建时间 commentId 回复评论id }] "),
                    @ResponseHeader(name="msg",description = "失败原因") })

    })
    public void getAdvCommentsById(){
        String id=getPara("id");
        int pageNumber=getParaToInt("pageNumber");
        ReqResponse<Page<Record>> r=new ReqResponse();
        Page<Record> record= advService.getAdvCommentsById(id,pageNumber);
        r.setData(record);
        renderJson(r);
    }

    @ApiOperation(url = "/v1/adv/getAdvRecommendByAdvId", tag = "adv", httpMethod = "post",description = "通过视频id获取相关推荐信息")
    @Params({
            @Param(name = "id", description = "视频id", required = true, dataType = "string")
    })
    @ApiResponses({
            @ApiResponse(code=200,message="成功",responseHeaders={
                    @ResponseHeader(name="code",description = " 0成功 1失败"),
                    @ResponseHeader(name="data",description = "headImg 头像   uid 自媒体或者企业id uName 用户名称 id 视频id coverImgSrc 图片地址 coverLink 图片链接    title 标题   type 类型  1自媒体 2企业广告3城市广告4传统文化 "),
                    @ResponseHeader(name="msg",description = "失败原因") })

    })
    public void getAdvRecommendByAdvId(){
        String id=getPara("id");
        ReqResponse<List<Record>> r=new ReqResponse();
        List<Record> record= advService.getAdvRecommendByAdvId(id);
        r.setData(record);
        renderJson(r);
    }
    @ApiOperation(url = "/v1/adv/getChinaList", tag = "adv", httpMethod = "post",description = "获取中国省市区列表")
    @Params({
            @Param(name = "version", description = "版本", required = true, dataType = "string")
    })
    @ApiResponses({
            @ApiResponse(code=200,message="成功",responseHeaders={
                    @ResponseHeader(name="code",description = " 0成功 1失败"),
                    @ResponseHeader(name="data",description = "{ provinces[code 编码 name 名称 ]  cities [code 编码 name 名称 provinceId  省id] areas [code 编码 name 名称 cityId 市id]}"),
                    @ResponseHeader(name="msg",description = "失败原因") })

    })
    public void getChinaList(){
        ReqResponse<Map<String,List<Record>>> r=new ReqResponse();
        Map<String,List<Record>> record= advService.getChinaList();
        r.setData(record);
        renderJson(r);
    }

    @ApiOperation(url = "/v1/adv/getCountryList", tag = "adv", httpMethod = "post",description = "获取海外国家列表")

    @ApiResponses({
            @ApiResponse(code=200,message="成功",responseHeaders={
                    @ResponseHeader(name="code",description = " 0成功 1失败"),
                    @ResponseHeader(name="data",description = "{ [code 编码 name 名称  ]}"),
                    @ResponseHeader(name="msg",description = "失败原因") })

    })
    public void getCountryList(){
        ReqResponse<List<Record>> r=new ReqResponse();
        List<Record> record= advService.getCountryList();
        r.setData(record);
        renderJson(r);
    }

    @ApiOperation(url = "/v1/adv/getCountryStateList", tag = "adv", httpMethod = "post",description = "获取国外州市列表 州和市都用此接口")
    @Params({
            @Param(name = "parentId", description = "父类id", required = true, dataType = "string")
    })
    @ApiResponses({
            @ApiResponse(code=200,message="成功",responseHeaders={
                    @ResponseHeader(name="code",description = " 0成功 1失败"),
                    @ResponseHeader(name="data",description = "{ [code 编码 name 名称 parentId 父类id ]}"),
                    @ResponseHeader(name="msg",description = "失败原因") })

    })
    public void getCountryStateList(){
        String parentId=getPara("parentId");
        ReqResponse<List<Record>> r=new ReqResponse();
        List<Record> record= advService.getCountryStateList(parentId);
        r.setData(record);
        renderJson(r);
    }*/
}
